/*
 * Copyright (c) 2010, Nikolaus Moll
 * All rights reserved.
 */
package net.miblounge.gradecalculator.importplugin.data;

public class UniversitySemester implements Comparable<UniversitySemester> {

	public enum Semester { SS, WS };
	
	private final Semester semester;
	private final int year;
	
	public UniversitySemester(final String text)
	{
		final String t = text.trim().replace(" ", "");
		
		semester = Semester.valueOf(t.substring(0, 2));
		year = Integer.parseInt(t.substring(2));
	}
	
	public UniversitySemester(final Semester semester, final int year)
	{
		this.semester = semester;
		this.year = year;
	}
	
	@Override
	public String toString()
	{
		return semester.toString() + " " + year;
	}
	
	public int compareTo(final UniversitySemester o) {
		final int yearComparison = this.year - o.year;
		if (yearComparison != 0) {
			return yearComparison;
		}
		
		if (this.semester == o.semester) {
			return 0;
		}
		
		if (this.semester == Semester.SS) {
			return -1;
		} else {
			return 1;
		}
	}

}
